package cn.csc.module.order.api.order;

import cn.csc.framework.common.pojo.CommonResult;
import cn.csc.framework.common.pojo.PageResult;
import cn.csc.module.order.api.order.dto.*;
import cn.csc.module.order.enums.ApiConstants;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.validation.Valid;
import java.math.BigInteger;
import java.util.List;
import java.util.Map;

/**
 * @author liuchuang
 * @version 1.0
 * @date 2024/1/25 9:50
 * @modify
 */
@FeignClient(name = ApiConstants.NAME) // TODO fallbackFactory =
@Api(tags = "RPC 服务 - 订单")
public interface OrderApi {

    String PREFIX = ApiConstants.PREFIX + "/order";


    /**
     * 获取订单状态，如果订单状态不存在，则说明订单没有创建
     *
     * @param orderIds 订单id列表
     * @return 订单状态
     */
    @GetMapping(PREFIX + "/getOrdersStatus")
    CommonResult<List<OrderStatusRespDTO>> getOrdersStatus(@RequestParam("orderIds") List<BigInteger> orderIds);


    /**
     * 买家订单列表-分页获取
     */
    @GetMapping(PREFIX +"/getOrderPage")
    @ApiOperation("订单列表信息查询")
    @ApiImplicitParam(name = "userId", value = "用户编号", required = true, example = "2048")
    CommonResult<PageResult<OrderRespDTO>> getOrderPage(@RequestParam("memberId") BigInteger memberId, @Valid OrderPageReqDTO pageVO);


    @GetMapping(PREFIX + "/getOrderDetail")
    @ApiOperation("获得订单详情页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "订单ID", required = true, example = "1024"),
            @ApiImplicitParam(name = "userId", value = "用户编号", required = true, example = "2048"),
    })
    CommonResult<OrderRespDTO> getOrderDetail(@RequestParam("orderId") BigInteger orderId,
                                              @RequestParam("memberId") BigInteger memberId);

    /**
     * 查询订单信息，包含订单子项
     */
    @GetMapping(PREFIX +"/getOrderWithItems")
    @ApiOperation("查询订单信息，包含订单子项")
    @ApiImplicitParam(name = "merchantOrderId", value = "商户订单ID", required = true, example = "2048")
    CommonResult<OrderWithItemRespDTO> getOrderWithItems(@RequestParam("merchantOrderId") String merchantOrderId);

    /**
     * 获取订单中的金额信息
     *
     * @param orderIds 订单id列表
     * @return 订单中的金额信息
     */
    @GetMapping(value = PREFIX + "/insider/getOrdersSimpleAmountInfo")
    CommonResult<List<OrderSimpleAmountInfoRespDTO>> getOrdersSimpleAmountInfo(@RequestParam("orderIds") List<BigInteger> orderIds);


    /**
     * 支付时更新订单状态
     * @param orderIds 订单id列表
     * @return null
     */
    @PutMapping(value = PREFIX + "/updateOrderState")
    CommonResult<Boolean> updateOrderState(@RequestParam("orderIds") List<BigInteger> orderIds, @RequestParam("orderStatus") Integer orderStatus);

    /**
     * 买家确认收货
     */
    @GetMapping(PREFIX + "/receipt")
    @ApiOperation("确认收货")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderId", value = "订单Id", required = true, example = "1024"),
            @ApiImplicitParam(name = "userId", value = "用户编号", required = true, example = "2048"),
    })
    CommonResult<String> updateReceipt(@RequestParam("orderId") BigInteger orderId,
                                              @RequestParam("memberId") BigInteger memberId);
    /**
     * 查询店铺下的已支付的订单总数
     */
    @GetMapping(PREFIX + "/getShopOrderNumber")
    @ApiOperation("查询店铺下的已支付的订单总数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "shopId", value = "店铺id", required = true, example = "1024"),
    })
    CommonResult<Long> getShopOrderNumber(@RequestParam("shopId") BigInteger shopId);

    @GetMapping(PREFIX + "/getCountByShopIds")
    @ApiOperation("通过店铺ID列表获取店铺的订单数")
    @ApiImplicitParam(name = "shopIds", value = "店铺id列表", required = true, example = "{12,13}")
    CommonResult<Map<String,Object>> getCountByShopIds(@RequestParam("shopIds") List<BigInteger> shopIds);

    @GetMapping(PREFIX + "/searchCartNum")
    @ApiOperation("查询 购物车商品数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户ID", required = true, example = "1024"),
    })
    CommonResult<Long> searchCartNum(@RequestParam("userId")  BigInteger userId);

}
